{literal}
var KONFIGURATOR_BASE_BEZUGSTOFFE = {
	praefix: '',
	description: '',
	err_msg: '',
	value: '-1',
	thmb_nochoose: window.KONFIGURATOR_IMGPATH_THMB + 'no-choose_thumb.jpg',

  init: function() {
  	$('#gallery_'+this.praefix+' div.thmb').click($.proxy(this.onChooseThmb, this));
		if ($.isPlainObject(this.value))
			$('#gallery_'+this.praefix+' div[rel="bezug-tabs"]').tabs();
		if (this.praefix == 'bezugstoffe_2') {
			$('#gallery_'+this.praefix+' span[name=equal-rear]').hide
			var _praefix = this.praefix;
			$.each(['front', 'rear'], function() {
				var dir = this;
				$('#gallery_'+_praefix).find('#selected-'+dir).click(function() {
					$('#gallery_'+_praefix).find('li[aria-controls="'+dir+'-tab"] a').click();
				});
			});
		}

{/literal}{if $FORM_ACTION == true}{literal}
  	KONFIGURATOR_objects.push(this.praefix.toUpperCase());
  	$('#gallery_'+this.praefix+' div.button-select').click($.proxy(this.onChange, this));
		if (this.praefix == 'bezugstoffe_2') {
			$('#gallery_'+this.praefix+' #front-tab div.thmb').click( function(){ 
				xajax_hasEqualRear( 
					$.param({pid:$('#cart_quantity input[name=products_id]').val(), 'bezug': $(this).find('img').attr('id')}) 
				); 
			});
			$('#gallery_'+this.praefix+' span[name=equal-front] input').click($.proxy(this.setEqualRear, this));
			this.enableEqualRear(false);
		}
  	this.addChooseThmbContainer();
{/literal}{/if}{literal}
  },
  
{/literal}{if $FORM_ACTION == true}{literal}
  addChooseThmbContainer: function() {
 		var c = $('#gallery ul.ad-thumb-list').children('li').length;
		if ($.isPlainObject(this.value)) {
			var cls = this;
			$.each([['front', 'Sitz'], ['rear', 'Lehne']], function(k,v) {
				$('#gallery ul.ad-thumb-list').append(
						'<li id="thmb_'+cls.praefix.toUpperCase()+'_'+v[0]+'" rel="konfigurator_option">'
					+ 	'<a class="thumb thumb'+(c+k)+'" href="" style="font-size: 10px; line-height: 18px; padding-top: 16px;">'
					+ 		'<img alt="'+cls.description+' / '+v[1]+'" class="image'+(c+k)+'" src="'+cls.thmb_nochoose+'" style="opacity: 0.6; margin-top: -35px; height:50px">'
					+			v[1]
					+ 	'</a>'
					+	'</li>'
				);

				$('#thmb_'+cls.praefix.toUpperCase()+'_'+v[0]).click(KONFIGURATOR_clickOnThmb);
			
			});
		}
		else {
			$('#gallery ul.ad-thumb-list').append(
					'<li id="thmb_'+this.praefix.toUpperCase()+'" rel="konfigurator_option">'
				+ 	'<a class="thumb thumb'+c+'" href="" style="font-size: 10px; line-height: 18px; padding-top: 16px;">'
				+ 		'<img alt="'+this.description+'" class="image'+c+'" src="'+this.thmb_nochoose+'" style="opacity: 0.6; margin-top: -35px; height:50px">'
				+			'Bezug'
				+ 	'</a>'
				+	'</li>'
			);
			
			$('#thmb_'+this.praefix.toUpperCase()).click(KONFIGURATOR_clickOnThmb);
		}
  },
  
	evalValue: function() {
		if ($.isPlainObject(this.value)) {
			if (this.value.front == '' || this.value.rear == '') {
				if (this.value.front + this.value.rear == '')
					return {'status':'failed', 'msg': 'Bitte w\u00E4hlen Sie einen Bezugstoff aus'};
				else
					return {'status':'failed', 'msg': 'Bitte w\u00E4hlen Sie den Bezugstoff f\u00FCr Sitz und Lehne aus'};
			}
		}
		else {
			if (this.value == '')
				return {'status':'failed', 'msg': 'Bitte w\u00E4hlen Sie einen Bezugstoff aus'};
		}
		return {'status':'okay'};
	},
	
	onChooseThmb_form: function(ev) {
		$('#gallery_'+this.praefix+' div.button-select').show();
	},

{/literal}{/if}{literal}

	loadFirstValue: function() { },

  onChooseThmb: function(ev) {
  	var side =	'';
		var side_tab = '';
  	var id =		$(ev.currentTarget).find('img').attr('id');
  	var src =		$(ev.currentTarget).find('img').attr('src').split('/');
  	var name =	$(ev.currentTarget).find('img').attr('alt');

  	id =  id.split('_');
  	side = id[2];
		if ($.isPlainObject(this.value)) side_tab = 'div.selected[rel='+side+'] ';
  	id = id.slice(id.length-3, id.length).join('_');
  	src = src[src.length-1];

		if ($.isPlainObject(this.value))
			$('#'+side+'-tab li div.thmb').removeClass('active');
		else
			$('#gallery_'+this.praefix+' li div.thmb').removeClass('active');
		
		$(ev.currentTarget).addClass('active');
  	
  	var imgSrc = $('#gallery_'+this.praefix+' ' + side_tab + 'img[name=thmb-select]').attr('src').split('/');
  	imgSrc[imgSrc.length-1] = src;

  	$('#gallery_'+this.praefix+' ' + side_tab + 'div[name=id-select]').html(id);
  	$('#gallery_'+this.praefix+' ' + side_tab + 'div[name=src-select]').html(src);
  	$('#gallery_'+this.praefix+' ' + side_tab + 'span[name=name-select]').html(name);
  	$('#gallery_'+this.praefix+' ' + side_tab + 'img[name=thmb-select]').attr({'src': imgSrc.join('/')});
  	this.onChooseThmb_form(ev);
  }
};
{/literal}